package 学生管理系统;

import java.util.ArrayList;
import java.util.Random;

public class 生成验证码 {
    public static void main(String[] args) {
        setCode();
    }
    private static void setCode() {
        // 创建一个集合 里面有大小写字母
        ArrayList<Character> list=new ArrayList<>();
        for (int i = 0; i < 26; i++) {
            list.add((char)('a'+i));
            list.add((char)('A'+i));
        }
        //System.out.println(list);
        Random r=new Random();
        String result="";

        for (int i = 0; i < 4; i++) {
            int randomIndex=r.nextInt(list.size());
            result+=list.get(randomIndex);
        }
        //System.out.println(result);
        int randomNumber=r.nextInt(10);
        result+=randomNumber;

        // 随机获取一个索引进行交换
        char[] arr=result.toCharArray();
        int randomindex2=r.nextInt(arr.length);

        char temp=arr[randomindex2];
        arr[randomindex2]=arr[arr.length-1];
        arr[arr.length-1]=temp;

        System.out.println(new String(arr));

    }
}
